/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package GoMail;

import SingleLinkedList.MySingleList;
import SingleLinkedList.SingleNode;
import java.io.*;

/**
 *
 * @author Administrator
 */
public class Contacts implements ContactsInterface
{
    private String name;
    private MySingleList mails;
    /**
     * Constructor is used to initailize new empty Contact object
     */
    public Contacts()
    {
        name = "";
        mails = new MySingleList();
    }
    /**
     * Constructor is used to initailize Contact object with contact name
     * @param n conatact name
     */
    public Contacts(String n)
    {
        name = n;
        mails = new MySingleList();
    }
    /**
     * This method is used to get list of  contact mails
     * @return list of  contact mails
     */
    public MySingleList getMails()
    {
        return mails;
    }
    /**
     * This method is used to set the list of contact mails
     * @param mails new list of  contact mails
     */
    public void setMails(MySingleList mails)
    {
        this.mails = mails;
    }
    /**
     * This method is used to get contact name
     * @return contact name
     */
    public String getName()
    {
        return name;
    }
    /**
     * This method is used to contact name
     * @param name new contact name
     */
    public void setName(String name)
    {
        this.name = name;
    }
    /**
     * This method is used to addMail to contact mail list
     * @param address new mail
     */
    public void addMail(String address)
    {
        mails.addElement(address);
    }
    /**
     * This method is used to get all contact mail
     * @return array of conatact mails
     */
    public String[] allMails()
    {
        SingleNode u = mails.getHead();
        String[]s = new String[mails.getSize()];
        int i = 0;
        while(i < s.length)
        {
            s[i] = (String)u.getData();
            u = u.getNext();
            i++;
        }
        return s;
    }
    /**
     * This method is used to contact data
     * This method is used when contact file is read
     * set Contact name and contact Mails
     * @param s array of strings that contains all contact data
     */
    public void setContactData(String[]s)
    {
        this.setName(s[0]);
        MySingleList contactMails = new MySingleList();
        int i = 0;
        while(i < s.length-1)
        {
            contactMails.addElement(s[i+1]);
            i++;
        }
        this.setMails(contactMails);
    }
    /**
     * This method is used to set contact mails only
     * this method is used when contact mails are edited
     * @param s array of contact mails
     */
    public void setContactMails(String[]s)
    {
        MySingleList contactMails = new MySingleList();
        int i = 0;
        while(i < s.length)
        {
            contactMails.addElement(s[i]);
            i++;
        }
        this.setMails(contactMails);
    }

}
